package com.king.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by Administrator on 2015/4/23.
 */
public class JavaFile {
    public static void main(String[] args) {
        FileOutputStream fileOutputStream = null;
        File file;
        String content = "this is a content built by java";
        try {
            file = new File("D:/写好的项目/a.txt");
            fileOutputStream = new FileOutputStream(file);
            if(file.exists()){
                file.createNewFile();
            }

            byte[] contentBytes = content.getBytes();
            fileOutputStream.write(contentBytes);
            //flush()强制将缓存区中的数据发送出去，不必等到缓存区满
            fileOutputStream.flush();
            fileOutputStream.close();
        }catch (IOException e){

            e.printStackTrace();
        }finally {
            try{
                if(fileOutputStream!=null){
                    fileOutputStream.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        System.out.println("java创建a.txt完成");


    }

}
